//
//  ViewController.m
//  GCAlertViewDemo
//
//  Created by 贺晓阳 on 2020/10/27.
//

#import "ViewController.h"
#import "GCAlertViewFeathers.h"
#import "GCAlertViewManager.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setFrame:CGRectMake(10, 100, [UIScreen mainScreen].bounds.size.width-20, 50)];
    [button setTitle:@"4s后的alert会清除前面的alert" forState:UIControlStateNormal];
    [button setBackgroundColor:[UIColor greenColor]];
    button.tag = 1001;
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];

    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [button2 setFrame:CGRectMake(10, 170, [UIScreen mainScreen].bounds.size.width-20, 50)];
    [button2 setTitle:@"4s后的alert不会清除前面的alert" forState:UIControlStateNormal];
    [button2 setBackgroundColor:[UIColor redColor]];
    button2.tag = 1002;
    [button2 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button2];
    
}

- (void)buttonAction:(UIButton *)btn {
    switch (btn.tag) {
        case 1001:
            [self doit];
            break;
        case 1002:
            [self doit2];
            break;
        default:
            NSLog(@"button没有配置行为");
            break;
    }
}


- (void)doit{
    
    for (int i = 0; i < 50; i++) {
        GCAlertViewFeathers *item = [[GCAlertViewFeathers alloc] init];
        [item setAlertViewClicked:^(NSInteger index) {
//            NSLog(@"%ld点击了",(long)index);
        }];
        item.weight = i;
        item.clearOther = NO;
        item.contentText = [NSString stringWithFormat:@"我的权重:%ld，sn:%d，是否清除综合权重比我小的弹框:%d",(long)item.weight, i+1, item.clearOther];
        [[GCAlertViewManager sharedAlertViewManager] insertAletViewItem:item];
    }
    
    [self performSelector:@selector(breakIt:) withObject:@1 afterDelay:4];

}

- (void)doit2{
    
    for (int i = 0; i < 50; i++) {
        GCAlertViewFeathers *item = [[GCAlertViewFeathers alloc] init];
        [item setAlertViewClicked:^(NSInteger index) {
//            NSLog(@"%ld点击了",(long)index);
        }];
        item.weight = i;
        item.clearOther = NO;
        item.contentText = [NSString stringWithFormat:@"我的权重:%ld，sn:%d，是否清除综合权重比我小的弹框:%d",(long)item.weight, i+1, item.clearOther];
        [[GCAlertViewManager sharedAlertViewManager] insertAletViewItem:item];
    }
    
    [self performSelector:@selector(breakIt:) withObject:@0 afterDelay:4];

}

- (void)breakIt:(NSNumber *)clear {
    
    for (int i = 0; i < 1; i++) {
        GCAlertViewFeathers *item = [[GCAlertViewFeathers alloc] init];
        [item setAlertViewClicked:^(NSInteger index) {
            //            NSLog(@"%ld点击了",(long)index);
        }];
        item.weight = 1000 + arc4random() % 100;
        item.clearOther = [clear boolValue];
        item.contentText = [NSString stringWithFormat:@"我的权重:%ld，sn:%d，是否清除综合权重比我小的弹框:%d",(long)item.weight, i+1, item.clearOther];
        [[GCAlertViewManager sharedAlertViewManager] insertAletViewItem:item];
    }
    
}

@end
